package java3_15.shangchang;

import java.util.Arrays;
import java.util.Scanner;

/**
 * 定义一个字符串数组，输入一个字符串,从数组中删除,
 * 删除后,后面的往前移动,注意置空的处理...
 * 比如字符串为{"aa","bb","cc","ff"},
 * 如果bb被删除后,则为{"aa","cc","ff",null}
 */
public class Delete {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String [] a = {"aa","bb","cc","ff"};
        System.out.println("请输入要删除的元素：");
        String x = scanner.next();
        for (int i = 0; i < a.length; i++) {
            if (x.equals(a[i])){
                if (i==a.length-1){
                    a[i] = null;
                }
                for (int j = i+1; j < a.length; j++) {
                    a[j-1] = a[j];
                    if (j==a.length-1){
                        a[j] = null;
                    }
                }
            }
        }
        System.out.println(Arrays.toString(a));
    }
}
